
#Creates xml parameter file for use on graphics program
#(c) Mike Hahn 2009
# for senior design 2 NIU MEE.


import xml.dom.minidom
from xml.dom.minidom import parse, parseString
import datetime
import time
class simprop():
    def __init__(self,FName,Ncars,Tstep,Tsim,Tracklength,maxAccel,desDecel,desVelo,accelExp,TsMean,TsStdev):
        doc1 = xml.dom.minidom.Document()
        data_element=doc1.createElement("Data")
        param_element=doc1.createElement("Parameters")
        comment_element=doc1.createElement("Comments")

        doc1.appendChild(data_element)
        data_element.appendChild(comment_element)
        data_element.appendChild(param_element)
        accel=doc1.createElement("maxAccel")
        filename=doc1.createElement("Filename")
        numcars=doc1.createElement("numcars")
        timestep=doc1.createElement("timestep")
        simtime=doc1.createElement("simtime")
        tracklength=doc1.createElement("tracklength")
        desvelo=doc1.createElement("desVelocity")
        desdecel=doc1.createElement("desdecel")
        delta=doc1.createElement("delta")
        tsmean=doc1.createElement("timemean")
        tsstddev=doc1.createElement("Tstanddev")
        date=doc1.createElement("date")
        info=doc1.createElement("About")

        t=time.localtime()
        x=str(t.tm_mon)+"-"+str(t.tm_mday)+"-"+str(t.tm_year)
        x=x+", "+str(t.tm_hour)+":"+str(t.tm_min)


        param_element.appendChild(accel)
        param_element.appendChild(filename)
        param_element.appendChild(numcars)
        param_element.appendChild(timestep)
        param_element.appendChild(simtime)
        param_element.appendChild(tracklength)
        param_element.appendChild(desvelo)
        param_element.appendChild(desdecel)
        param_element.appendChild(delta)
        param_element.appendChild(tsmean)
        param_element.appendChild(tsstddev)
        comment_element.appendChild(date)
        comment_element.appendChild(info)

        accel.setAttribute("a",str(maxAccel))
        filename.setAttribute("FName",str(FName))
        numcars.setAttribute("Ncars",str(Ncars))
        timestep.setAttribute("Tstep",str(Tstep))
        simtime.setAttribute("Tsim",str(Tsim))
        tracklength.setAttribute("Tlength",str(Tracklength))
        desvelo.setAttribute("desVelo",str(desVelo))
        desdecel.setAttribute("b",str(desDecel))
        delta.setAttribute("accelExp",str(accelExp))
        tsmean.setAttribute("TsMean",str(TsMean))
        tsstddev.setAttribute("TsStdev",str(TsStdev))
        date.setAttribute("Created",x)
        info.setAttribute("About","This file was created by the Traffic Wave Propagation Siumulation GUI (c) Mike Hahn, Mikelhahn@gmail.com, 2009")

        datawrite=open("params.xml","w")
        datawrite.write(doc1.toprettyxml())
        datawrite.close()
